home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 March / CMCD0305.ISO / Software / Shareware / Utilitare / emu / Emu8086_Setup_307c.exe / {app} / Samples / fahrenheit.asm < prev    next >
Assembly Source File  |  2002-11-15  |  1KB  |  59 lines

  1.  
  2. ; Centigrade (Celsius) to Fahrenheit
  3. ; calculation and vice-versa.
  4. ; (not very accurate, since using
  5. ; integer divide, it may not work
  6. ; for some values as well...).
  7.  
  8. ; This program has no input/output from
  9. ; the user, so in order to see the result
  10. ; it maybe useful to select "Variables"
  11. ; from "View" menu of the emulator.
  12.  
  13. ; Another way to see the output is to
  14. ; use PRINT_NUM procedure from "emu8086.inc",
  15. ; see "Part 5" in tutorials.
  16. ; (since we get result in AL, you should use
  17. ; CBW instruction before printing out,
  18. ; because PRINT_NUM prints a signed number
  19. ; in AX register).
  20.  
  21. #MAKE_COM#
  22.  
  23.  
  24. ORG 100h
  25.  
  26. JMP start
  27.  
  28. tc DB 10    ; t Celsius.
  29. tf DB 0     ; t Fahrenheit.
  30.  
  31. result1 DB ?   ; result in Fahrenheit.
  32. result2 DB ?   ; result in Celsius.
  33.  
  34. start:
  35.  
  36. ; convert Celsius to Fahrenheit according
  37. ; to this formula: f = c * 9 / 5 + 32
  38.  
  39. MOV CL, tc
  40. MOV AL, 9
  41. IMUL CL
  42. MOV CL, 5
  43. IDIV CL
  44. ADD AL, 32
  45. MOV result1, AL
  46.  
  47. ; convert Fahrenheit to Celsius according
  48. ; to this formula: c = (f - 32) * 5 / 9
  49.  
  50. MOV CL, tf
  51. SUB CL, 32
  52. MOV AL, 5
  53. IMUL CL
  54. MOV CL, 9
  55. IDIV CL
  56. MOV result2, AL
  57.  
  58. RET
  59.